﻿import QtQuick 2.0
import "../components"
Rectangle {
    width: parent.width
    height: parent.height
    radius: 12
    color: "white"
    Connections{
        target: CSignal
        onVoiceAssistant:{     // 通信状态
            if(status===0){
                speechModToast.show("连接成功",0);
            }
            else{
                speechModToast.show("连接失败",1)
            }
        }
    }

    CustomComboBox{
        id:serialPort
        x:(parent.width-width)/2
        y:60*dp
        titleWidth: 100*dp
        editWidth: 200*dp
        title: "语音模块选择"
        model: GetMessageInterface.getSerialPort()
    }
    onVisibleChanged: {
        if(visible){
//            connectType = 0
            var data=GetMessageInterface.getSpeechUseInfo();
            if(data===1){
                textv.text="是"
                button_autoExport.checked=true
            }else{
                textv.text="否"
                button_autoExport.checked=false
            }
        }
    }
    Text {
        x:parent.width/2-120*dp
        width: 80*dp
        y: 140*dp
        text: qsTr("是否开启")
        font.pixelSize: config.fontsize
    }
    CustomSwitchButton{
        x:parent.width/2-50*dp
        y:138*dp
        width: 40*dp
        height: 25*dp
        id: button_autoExport
        checked: true
        CustomTooltip{
            visible: parent.isHovered
            text: "是否默认"
        }
        onClicked: {
            if(checked){
                textv.text="是"
                GetMessageInterface.setSpeechUseInfo("1")
            }else{
                textv.text="否"
                GetMessageInterface.setSpeechUseInfo("0")
            }
        }
    }
    Text {
        id:textv
        x:parent.width/2+5*dp
        y: 140*dp
        text: qsTr("是")
        font.pixelSize: config.fontsize
    }
    PushButton{
        width: 120*dp
        height: 40*dp
        x:parent.width/2-width/2
        y:parent.height*0.4
        title: "确认"
        defaultMode1: true
        onReleased: {
            GetMessageInterface.connectSpeechMode(serialPort.getText());
        }
    }
    Toast{
        id: speechModToast
        x: (parent.width-width) * 0.5
        y: 10*dp
    }
}
